<template>
  <div id="shop-item">
    <div class="item-selector">
      <CheckButton
        @checkBtnClick="checkedChange"
        v-model="itemInfo.checked"
      ></CheckButton>
    </div>
    <div class="item-img">
      <img :src="itemInfo.image" alt="商品图片" />
    </div>
    <div class="item-info">
      <div class="item-title">{{ itemInfo.title }}</div>
      <div class="item-desc">{{ itemInfo.desc }}</div>
      <div class="info-bottom">
        <div class="item-price left">¥{{ itemInfo.price }}</div>
        <button class="right del" @click="delItem">删除</button>
        <div class="counter">
          <button class="right item-count" @click="itemInfo.count++">+</button>
          <div class="item-count right">{{ itemInfo.count }}</div>
          <button
            class="right item-count"
            @click="itemInfo.count--"
            :disabled="itemInfo.count <= 1"
          >
            -
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import CheckButton from "components/content/checkButton/CheckButton";

export default {
  name: "ShopCartItem",
  props: {
    itemInfo: Object,
    default() {
      return {};
    },
  },
  components: {
    CheckButton,
  },
  methods: {
    checkedChange: function () {
      this.itemInfo.checked = !this.itemInfo.checked;
    },
    //删除指定的商品
    delItem() {
      // this.$store.state.cartList.splice(this.itemInfo);
      this.$emit("delItem");
    },
  },
};
</script>

<style scoped>
#shop-item {
  width: 100%;
  display: flex;
  font-size: 0;
  padding: 5px;
  border-bottom: 1px solid #ccc;
}

.item-selector {
  width: 20px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.item-title,
.item-desc {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.item-img {
  padding: 5px;
  /*border: 1px solid #ccc;*/
}

.item-img img {
  width: 80px;
  height: 100px;
  display: block;
  border-radius: 5px;
}

.item-info {
  font-size: 17px;
  color: #333;
  padding: 5px 10px;
  position: relative;
  overflow: hidden;
}

.item-info .item-desc {
  font-size: 14px;
  color: #666;
  margin-top: 15px;
}

.info-bottom {
  margin-top: 10px;
  position: absolute;
  bottom: 10px;
  left: 10px;
  right: 10px;
}

.info-bottom .item-price {
  color: orangered;
}

.item-count {
  /* text-align: center; */
  display: flex;
  justify-content: center;
  align-items: center;
  width: 20px;
  height: 20px;
}

.counter button {
  border: 1px solid #ccc;
  /* color: #fff; */
}

.del {
  background-color: var(--color-tint);
  width: 50px;
  height: 30px;
  border: none;
  color: aliceblue;
}
.counter {
  float: left;
  width: 70px;
  height: 25px;
  margin-right: 20px;
}
</style>
